import instance from '@/assets/js/utils'
/*注册vux组件 */
import {
    Alert,
    Cell,
    CellBox,
    CheckIcon,
    ConfirmPlugin,
    Datetime,
    Grid,
    GridItem,
    Group,
    Loading,
    LoadMore,
    Popup,
    PopupPicker,
    PopupHeader,
    PopupRadio,
    Tab,
    TabItem,
    Toast,
    ToastPlugin,
    TransferDom,
    XCircle,
    XHeader,
    XTextarea,
    XButton,
    LoadingPlugin,
    Swiper,
    SwiperItem,
    XProgress,
} from 'vux';

/*注册自定义组件 */
import accordion from '@/components/accordion'
import DeptTree from '@/components/tree/deptTree'
import detailTable from '@/components/table/detailTable'
import SideBar from '@/components/sidebar/sideBar'
import SimpleSearch from "@/components/search/simpleSearch"
import PersonTree from '@/components/tree/personTree'
import PhotoUpload from '@/components/file-upload/photoUpload'
import PictureUpload from '@/components/file-upload/pictureUpload'
/*引入scroller组件 */
import VueScroller from 'vue-scroller'
/*引入svgIcon*/
import Icon from 'vue-svg-icon/Icon'
import store from '@/store';

/*引入utils方法 */
import {
    getReqUrl,
    downloadFile,
    getTaskParams,
    getRiskParams,
    guid,
    pattern,
    toTree,
} from './utils';

let DEV_FLAG = true;
let prodUrl = process.env.BASE_URL

export default {
    install: function(Vue, options) {
        if (DEV_FLAG) {
            Vue.prototype.baseUrl = '/'
        } else {
            Vue.prototype.baseUrl = prodUrl
        }
        Vue.prototype.SXDTPM_URL = Vue.prototype.baseUrl + "qhszpm/servlet/Action.cmd";
        Vue.prototype.COMMON_URL = Vue.prototype.baseUrl + "qhszpm/servlet/Action.cmd";
        Vue.prototype.LOGIN_URL = Vue.prototype.baseUrl + "qhszpm/servlet/LoginServlet.cmd";
        Vue.prototype.FORM2SUBSYS_SUPPORT_URL = Vue.prototype.baseUrl + "qhszpm/servlet/StreamSupportAction.cmd";

        Vue.prototype.$ajax = instance
        Vue.prototype.downloadFile = downloadFile

        Vue.component('cell', Cell)
        Vue.component('check-icon', CheckIcon)
        Vue.component('datetime', Datetime)
        Vue.component('grid', Grid)
        Vue.component('grid-item', GridItem)
        Vue.component('cell-box', CellBox)
        Vue.component('group', Group)
        Vue.component('loading', Loading)
        Vue.component('load-more', LoadMore)
        Vue.component('popup', Popup)
        Vue.component('popup-picker', PopupPicker)
        Vue.component('popup-header', PopupHeader)
        Vue.component('popup-radio', PopupRadio)
        Vue.component('tab', Tab)
        Vue.component('tab-item', TabItem)
        Vue.component('toast', Toast)
        Vue.directive('transfer-dom', TransferDom)
        Vue.component('x-circle', XCircle)
        Vue.component('x-header', XHeader)
        Vue.component('x-textarea', XTextarea)
        Vue.use(ConfirmPlugin)
        Vue.use(ToastPlugin)
        Vue.use(LoadingPlugin)
        Vue.component('simple-search', SimpleSearch)
        Vue.component('photo-upload', PhotoUpload)
        Vue.component('picture-upload', PictureUpload)
        Vue.component('accordion', accordion)
        Vue.component('person-tree', PersonTree)
        Vue.component('dept-tree', DeptTree)
        Vue.component('detail-table', detailTable)
        Vue.component('side-bar', SideBar)
        Vue.use(VueScroller)
        Vue.component('icon', Icon)
        Vue.component('alert', Alert)
        Vue.component('x-button', XButton)
        Vue.component('swiper', Swiper)
        Vue.component('swiper-item', SwiperItem)
        Vue.component('x-progress', XProgress)

        Vue.prototype.getReqUrl = getReqUrl //获取请求加密参数
        Vue.prototype.getTaskParams = getTaskParams //获取不同服务器表单参数
        Vue.prototype.getRiskParams = getRiskParams
        Vue.prototype.guid = guid //获取guid
        Vue.prototype.toTree = toTree //数组转换成树
        Date.prototype.pattern = pattern

        //强制关闭遮盖层
        Vue.prototype.closeMask = function() {
            let mask = document.querySelector('.vux-popup-mask')
            mask.classList.remove('vux-popup-show')
            setTimeout(() => {
                mask && !/show/.test(mask.className) && (mask.style['zIndex'] = -1)
            }, 400)
            if (store.state.defaultPop) {
                store.commit("CHANGE_DEFAULT_POPUP")
            }
        }

        //   //登出
        //   Vue.prototype.loginOut = function () {
        //     this.$router.push('/')
        //   }

        //获取用户
        Vue.prototype.getPerson = function(username, type, callback) {
            this.$ajax({
                    method: 'post',
                    url: this.COMMON_URL + '?_method=V_USER_SELECT*getHRUserListSec&type=prj',
                    data: {
                        "MiniQueryFormData": '{"RoleId":"","GroupId":"","UserFullName":"' + username + '"}',
                        "pageIndex": "0",
                        "pageSize": "1000",
                        "sortField": "USER_FULLNAME",
                        "sortOrder": "asc"
                    }
                }).then((res) => {
                    callback(res)
                })
                .catch((err) => {
                    console.log(err)
                })
        }

        //获取token
        //   Vue.prototype.getToken = function (username, password) {
        //     this.$http({
        //       method: 'post',
        //       url: TOKEN_URL + "?username=" + username + "&password=" + password,
        //       data: {}
        //     }).then((res) => {
        //       if (res.data.code == 200) {
        //         window.localStorage.setItem("token", res.data.msg);
        //         this.$store.dispatch('getUserInfo')
        //         this.$store.dispatch('getNews')
        //         this.$store.dispatch('getDept', {
        //           id: 0
        //         })
        //       }
        //     })
        //     .catch((err) => {
        //         console.log(err)
        //     })
        //   }

        //格式国际标准时间格式为200-mm-dd 放回日期和时间 分钟
        //   Vue.prototype.formatDatee = formatDatee
        //   Vue.prototype.formatDate = formatDate
        //判断对象为空
        Vue.prototype.isEmptyObject = (e) => {
            var t;
            for (t in e)
                return !1;
            return !0
        }
    }
};